<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    function ping(ip){
        var img = new Image();
        var start = new Date().getTime();
        img.src = "http://" + ip + "?t=" + start;
        var flag = false;  //无法访问
        img.onload = function(){
            flag = true;
            console.log('ok');
        };
        img.onerror = function(){
            flag = true;
            console.log('ok');
        };
        var timer = setTimeout(function(){
            if(!flag){    //如果真的无法访问
                flag = false;
                console.log('failed');
            }
        },1500);
    }
    ping('192.168.22.7')
</script>